/**
 * @param {number[]} arr
 * @param {number} k
 * @return {number}
 */
var maxSumAfterPartitioning = function (arr, k) {
    const len = arr.length
    let dp = Array(len+1).fill(0)
    let maxValue
    for (let i = 1; i <= len; i++) {
       maxValue = arr[i-1]
       for(let j=i-1;j>=Math.max(0,i-k);j--){
         dp[i]=Math.max(dp[i],dp[j]+maxValue*(i-j))
         if(j>0){
           maxValue=Math.max(maxValue,arr[j-1])
         }
       }
      
    }
    return dp[len]
};


maxSumAfterPartitioning([1,15,7,9,2,5,10],3)